package com.novellotus.iov.carvice.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.novellotus.iov.carvice.R;
import com.novellotus.iov.carvice.model.ModifyMobileModel;
import com.novellotus.iov.carvice.utils.MyUtils;
import com.novellotus.iov.carvice.utils.SharedPreferencesUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 修改手机页面
 */
public class ModifyMobileActivity extends BaseActivity {

    @BindView(R.id.tv_tittle)
    TextView tv_tittle;
    @BindView(R.id.btn_right)
    Button btn_right;
    @BindView(R.id.tv_tips)
    TextView tv_tips;
    @BindView(R.id.tv_tips2)
    TextView tv_tips2;
    @BindView(R.id.tv_phone)
    TextView tv_phone;
    @BindView(R.id.btn_code)
    Button btn_code;
    @BindView(R.id.edt_mobile)
    EditText edt_mobile;
    @BindView(R.id.edt_code)
    EditText edt_code;

    ModifyMobileModel modifyMobileModel;

    @Override
    protected void initContentView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_modify_phone);
    }

    @Override
    public void init() {
        tv_tittle.setText("修改手机");
        btn_right.setText("确定");
        String mobile = SharedPreferencesUtils.getUser(this)[1];
        if (!mobile.equals("") && MyUtils.isMobile(mobile)) {
            tv_phone.setText(mobile);
        } else {
            tv_tips.setVisibility(View.INVISIBLE);
            tv_phone.setText("您暂时还没有设置手机号");
            tv_tips2.setText("设置后，下次可以使用手机号登录!");
        }
        modifyMobileModel = new ModifyMobileModel(this);
        modifyMobileModel.setMobileEditText(edt_mobile, btn_code,SharedPreferencesUtils.getUser(this)[3]);
        modifyMobileModel.setCode(edt_code);
        modifyMobileModel.setBtnCode(btn_code, edt_mobile);
        modifyMobileModel.setConfirm(btn_right);
        modifyMobileModel.changeMobile(btn_right, edt_mobile, edt_code);
    }

    @OnClick(R.id.img_back)
    void back() {
        MyUtils.hideInput(this);
        finish();
    }

    @OnClick(R.id.btn_right)
    void btnSure() {
        modifyMobileModel.changeMobile(btn_right, edt_mobile, edt_code);
    }

}
